window.onload=function(){
    TabBar('my')
    //获取用户信息
    axios.defaults.withCredentials = true;
     //登录
     let kh_goup=document.getElementById("kh_goup")
     let kh_username=document.getElementById("kh_username")
    
     kh_goup.addEventListener('click',()=>{
         window.location.href='/pages/Singin/singin.html'
     })
 
    axios.get('https://elm.cangdu.org/v1/user').then(res => {
 
        console.log(res);
        let newname=decodeURIComponent(location.search).substring(9)
        console.log(newname);
       
        
        if(res.data.status==0){
            kh_username.innerHTML='登陆/注册'
            kh_goup.addEventListener('click',()=>{
                window.location.href='/pages/Singin/singin.html'
            })
        }
       else{
        $('#kh_ye').html(`${res.data.balance}.00`)
        $('#kh_yh').html(`${res.data.gift_amount}`)
        $('#kh_jf').html(`${res.data.point}`)
        kh_username.innerHTML=res.data.username 
        // if(newname.length>0){
        //     kh_username.innerHTML=newname
        // }else if(newname==0){
        //     kh_username.innerHTML=res.data.username 
        // }
       let newname=window.localStorage.getItem('newname')
       console.log(newname);
       if(newname.length==0){
        kh_username.innerHTML=res.data.username
       }
       else{
        kh_username.innerHTML=newname
       }
    //    if()
        $('#kh_touxiang').html(
            ` <img src="//elm.cangdu.org/img/${res.data.avatar}" id='kh_changeimg'>`
            )
        kh_goup.addEventListener('click',()=>{
            window.location.href=`/pages/uesr/uesr.html?newname=${newname}`
            
        })
       }
    
    })
    //余额优惠积分
    let kh_mycount1=document.getElementsByClassName("kh_mycount1")
    kh_mycount1[0].addEventListener('click',()=>{
        window.location.href='/pages/function/mycount.html'
    })

    kh_mycount1[1].addEventListener('click',()=>{
        
        window.location.href='/pages/function/myyouhui.html'
    })

    kh_mycount1[2].addEventListener('click',()=>{
        window.location.href='/pages/function/myjf.html'
    })

    //我的订单跳转
    let =document.getElementById("kh_mydindan")
    kh_mydindan.addEventListener('click',()=>{
        window.location.href='/pages/order/order.html'
    })
  
  
  
}